<template>
    <div class="registerf" id="form1">
        <form @submit.prevent="submit">
            <!--注册费-->
            <div class="reg" v-for="(item,index) in author">
                <div class="regtop">
                    <i class="bg"></i><span class="tx">注册费</span>
                  <a @click="regpayc(index)" v-if="item.show===1" class="submit" :class="{submit_del:item.show}">删除</a>
                  <a @click="regpayc(index)" v-else-if="item.show===false" class="submit">缴费</a>
                  <a v-else-if="item.show===2" class="submit" style="background-color: #fff"></a>
                </div>
                <div class="regcenter">
                    <i class="bg"></i><span class="tx">基础费用:{{item.ticket_price}}</span> <a class="submit">超页费:{{item.exceed_fee}}</a>
                </div>
                <div v-if="item.show===1">
                    <div class="registerf_hi">
                        <p class="registerf_t">作者信息</p>
                        <div class='calll'>
                            <div class='left cal'>姓名</div>
                            <div class='left car'><input type='text' name="regname" placeholder='' required="required" v-model="regArr.data[0].name"></div>
                        </div>
                        <div class='calll'>
                            <div class='left cal'>手机号码</div>
                            <div class='l eft car'><input type='number'  name="regphone" placeholder='' required="required" v-model="regArr.data[0].phone"></div>
                        </div>
                        <div class='calll'>
                            <div class='left cal'>邮箱</div>
                            <div class='left car'><input type='email' name="regemail" placeholder='' required="required" v-model="regArr.data[0].email"></div>
                        </div>
                    </div>
                    <p>可缴费稿件</p>
                    <div class="reg_radio">
                        <!--<mt-radio v-model="value" :options="options"  @change="paydraft()">-->
                        <!--</mt-radio>-->
                        <!--v-model="regArr.female"-->
                        <div class="femalew"  v-for="(female,index) in femalearr">
                            <label>
                                <input type="checkbox" name="females" @change="femalec(index)" :value="index"/>《{{female.title}}》
                            </label>
                            <div class="reg_int" v-if="female.show">论文总页数：<input type="number" v-on:input="reg_num(index)" v-model="female.reg_num" :name="'reg_num'+index" required="required" class="reg_num"/>页，基础&nbsp;{{female.femalenum}}&nbsp;页，超页数<input type="number" :name="'reg_numc'+index" v-model="female.reg_numb" readonly class="reg_num"/>页。</div>
                        </div>
                        <div class="reg_radiob">
                            <div class="gin_left">参会</div>
                            <div class="gin_right">
                                <label><input type="radio" value="0" name="reggin" v-model="regArr.data[0].picked" required="required" @change="pickeds"/>是</label>
                                <label><input type="radio" value="1" name="reggin" v-model="regArr.data[0].picked" required="required" @change="pickeds"/>否</label>
                            </div>
                        </div>
                        <div class="reg_radiob_hide" v-if="regArr.data[0].picked==0">
                            <div class="reg_radiob">
                                <div class="gin_left">用餐</div>
                                <div class="gin_right">
                                    <label><input type="radio" value="0" name="regmeal" v-model="regArr.data[0].regmeal" required="required"/>是</label>
                                    <label><input type="radio" value="1" name="regmeal" v-model="regArr.data[0].regmeal" required="required">否</label>
                                </div>
                            </div>
                            <div class="reg_radiob">
                                <div class="gin_left">性别</div>
                                <div class="gin_right">
                                    <label><input type="radio" value="0" name="regsex" v-model="regArr.data[0].regsex" required="required"/>男</label>
                                    <label><input type="radio" value="1" name="regsex" v-model="regArr.data[0].regsex" required="required"/>女</label>
                                </div>
                            </div>
                            <div class="reg_radiob">
                                <div class="gin_left">代预约酒店</div>
                                <div class="gin_right">
                                    <label><input type="radio" value="0" name="reghotel" v-model="regArr.data[0].reghotel" required="required"/>是</label>
                                    <label><input type="radio" value="1" name="reghotel" v-model="regArr.data[0].reghotel" required="required"/>否</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--参会费-->
            <!--<ul>-->
            <!--<li v-for="(site,index) in sites">-->
            <!--{{index+1}}.{{site}}-->
            <!--</li>-->
            <!--</ul>-->
            <div class="meeting" v-for="(item,index) in involution">
                <div class="regtop">
                    <i class="bg"></i><span class="tx">参会费</span> <a @click="addsubmitw(index)" class="submit" :class="{meeting_del:meetingc==2}">缴费</a>
                </div>
                <div class="regcenter">
                    <i class="bg"></i><span class="tx">{{item.ticket_price}}</span>
                </div>
                <div class="meeting_n" v-if="item.show" v-for="(meet,index) in meetingArr">
                    <div class="registerf_hi">
                        <p class="registerf_t">参会者&nbsp;{{index+1}}</p>
                        <div class='calll'>
                            <div class='left cal'>姓名</div>
                            <div class='left car'><input type='text' name="name" placeholder='' v-model="meet.name" required="required"></div>
                        </div>
                        <div class='calll'>
                            <div class='left cal'>手机号码</div>
                            <div class='l eft car'><input type='number'  name="phone" placeholder='' v-model="meet.phone" required="required"></div>
                        </div>
                        <div class='calll'>
                            <div class='left cal'>邮箱</div>
                            <div class='left car'><input type='email' name="email" placeholder='' v-model="meet.email" required="required"></div>
                        </div>
                    </div>
                    <div class="reg_radio">
                        <div class="reg_radiob">
                            <div class="gin_left">用餐</div>
                            <div class="gin_right">
                                <label><input type="radio" value="0" :name="'ca'+index" v-model="meet.ca" required="required"/>是</label>
                                <label><input type="radio" value="1" :name="'ca'+index" v-model="meet.ca" required="required"/>否</label>
                            </div>
                        </div>
                        <div class="reg_radiob">
                            <div class="gin_left">性别</div>
                            <div class="gin_right">
                                <label><input type="radio" value="0" :name="'sex'+index" v-model="meet.sex" required="required"/>男</label>
                                <label><input type="radio" value="1" :name="'sex'+index" v-model="meet.sex" required="required"/>女</label>
                            </div>
                        </div>
                        <div class="reg_radiob">
                            <div class="gin_left">代预约酒店</div>
                            <div class="gin_right">
                                <label><input type="radio" value="0" :name="'host'+index" v-model="meet.host" required="required"/>是</label>
                                <label><input type="radio" value="1" :name="'host'+index" v-model="meet.host" required="required"/>否</label>
                            </div>
                        </div>
                        <div class="reg_radiob" style="text-align: right;">
                            <a @click="addsubmit(index)" class="submit addsubmit">新增</a>
                            <a @click="meetingpayc(index)" class="submit delsubmit">删除</a>
                        </div>
                    </div>
                </div>
            </div>
            <!--底部-->
            <div class="bottom">
                <div class="bottom_f">合  计：<span>¥&nbsp;{{total}}</span></div>
                <div class="bottom_r">
                    <input type="submit" value="结算">
                    <!--<router-link to="/order">结算</router-link>-->
                </div>
            </div>
        </form>
    </div>
</template>
<script>
    import {Toast,Indicator} from 'mint-ui';
    import {RequestPost} from '@/api/http.js'
    export default {
        name: "registerf",
        data () {
            return {
                data:{
                  id:null,
                },
                author:[],
                involution:[],
                femalearr:[],
                getUbdex:0, // 缴费按钮状态
                base_num:0,//基础费用
                super_num:0, //超页费用
                join_num:0,//参会费用
                total:0,//总数
                regpay:'缴费',//注册费
                regpayt:0,//注册费
                meetingc:1,//参会费
                femalel:'a',//注册费缴费 可选缴费
                reg_numc:0,//超页总数
                pages:[], //页数数组
                paydraf:'无',
                picked:'a',
                female_reg_num:null,
                regArr:{data:[]},//注册费表单数组
                meetingArr: [],//参会费表单数组
                papert:[],//稿件
                involution_id:null,//参会id
                base_numb:0,//注册费 页数
            }
        },
        beforeCreate(){
            // console.log('beforeCreate:刚刚new Vue()之后，这个时候，数据还没有挂载呢，只是一个空壳')
            // console.log(this.msg)//undefined
            // console.log(document.getElementsByClassName("myp")[0])//undefined
        },
        created(){
          let storage = JSON.parse(localStorage.getItem('login'));
          this.data.id =  this.$route.query.mid
          RequestPost({url:'/meeting/getRegfee',data:{mid:this.data.id,uid:storage.id}}).then((response) => {
            this.author=response.data.data.author
            this.involution=response.data.data.involution
            this.femalearr=response.data.data.paper
            console.log(response.data)

          }).catch(err => {
            Toast({
              message: '获取数据失败',
              duration: 3000
            });
          })


          this.rtotal();
            // console.log('created:这个时候已经可以使用到数据，也可以更改数据,在这里更改数据不会触发updated函数')
            // this.msg+='!!!'
            // console.log('在这里可以在渲染前倒数第二次更改数据的机会，不会触发其他的钩子函数，一般可以在这里做初始数据的获取')
            // console.log('接下来开始找实例或者组件对应的模板，编译模板为虚拟dom放入到render函数中准备渲染')
        },
        beforeMount(){
            // console.log('beforeMount：虚拟dom已经创建完成，马上就要渲染,在这里也可以更改数据，不会触发updated')
            // this.msg+='@@@@'
            // console.log('在这里可以在渲染前最后一次更改数据的机会，不会触发其他的钩子函数，一般可以在这里做初始数据的获取')
            // console.log(document.getElementsByClassName("myp")[0])//undefined
            // console.log('接下来开始render，渲染出真实dom')
        },
        // render:function(createElement){
        //     console.log('render')
        //     return createElement('div','hahaha')
        // },
        mounted(){
            Indicator.close();
            // submitForm(formName) {
            //   this.$refs[formName].validate(valid => {
            //     if (valid) {
            //       //如果通过验证 to do...
            //     } else {
            //       console.log('error submit!!')
            //       return false
            //     }
            //   })
            // }
            // console.log('mounted：此时，组件已经出现在页面中，数据、真实dom都已经处理好了,事件都已经挂载好了')
            // console.log(document.getElementsByClassName("myp")[0])
            // console.log('可以在这里操作真实dom等事情...')
            //  let officer_li = document.getElementsByClassName('officer-li');
            // officer_li.onclick(function() {
            //   for (let i = 0; i<officer_li.length; i++) {
            //    console.log(11)
            //   }
            // })

            //    this.$options.timer = setInterval(function () {
            //        console.log('setInterval')
            //         this.msg+='!'
            //    }.bind(this),500)
        },
        methods: {
            // 注册费 缴费
            regpayc:function(index){
                if(this.author[index].show===1){ //判断缴费按钮现在是否是删除
                  this.regpayt=1
                  this.base_num=0
                  this.regArr.data=[]
                  this.super_num=0
                  this.base_numb=0
                  for (let i =0;i<this.author.length;i++){
                      this.author[i].show = false
                      console.log('改回来')
                  }
                  for(var i = 0;i<this.femalearr.length;i++)
                  {
                    this.femalearr[i].reg_numb=0;
                    this.femalearr[i].reg_num=null;
                    this.femalearr[i].show=false;
                  }
                      console.log('关闭执行')
                }else {
                  this.base_num=parseInt(this.author[index].ticket_price)
                  this.super_num=parseInt(this.author[index].exceed_fee)
                  this.regArr.data.push({id:this.author[index].id})
                  this.author[index].show=1
                  this.regpayt=2
                  this.base_numb=1
                  console.log(this.author)
                  for (let i =0;i<this.author.length;i++){
                    if (this.author[i].show===false){
                      this.author[i].show = 2
                      console.log('其它的改为2')
                    }
                  }
                }
              this.rtotal();
            },
            //注册费 缴费稿件选项
            femalec:function (index) {
              // let papert = this.papert
              // this.papert=[]
                this.femalearr[index].show=!this.femalearr[index].show;
                console.log(this.author)

            },
            //参会费 新增 缴费
            addsubmitw:function(index){
              if (this.meetingc==1){
                this.meetingc=2
              }
              this.join_num=parseInt(this.involution[index].ticket_price)
              this.involution.id =this.involution[index].id
              let meelengs  = this.meetingArr.length
              this.involution[index].show= true
              this.meetingArr.push({id:this.involution_id,test:''})
              this.rtotal();
            },
            addsubmit:function(index){
              let meelengs  = this.meetingArr.length
              this.meetingArr.push({id:this.involution_id,test:''})
              this.rtotal();
            },
            meetingpayc:function(index){
                if (this.meetingArr.length==1){
                    if (this.meetingc==2){
                        this.meetingc=1
                      for (let i =0;i<this.involution.length;i++){
                        this.involution[i].show = false
                        console.log('改回来')
                      }
                    }
                }
                this.meetingArr.splice(index,1);
                this.rtotal();
            },
            meeting_del:function(index){

            },
            pickeds:function(){

            },
            reg_num:function(index){
                let reg_num = parseFloat(this.femalearr[index].reg_num)
                if (reg_num<1) {
                  this.femalearr[index].reg_num=null
                  Toast({
                    message: '页数最少为1页',
                    duration: 3000
                  });
                }
                else if (Number.isInteger(reg_num)===false) {
                  this.femalearr[index].reg_num=null
                  this.femalearr[index].reg_numb=0
                Toast({
                  message: '请输入整数',
                  duration: 3000
                });
              }
                else if (reg_num>this.femalearr[index].femalenum) {
                    this.femalearr[index].reg_numb=reg_num-this.femalearr[index].femalenum;
                }else {
                    this.femalearr[index].reg_numb=0
                }
              this.rtotal();
              console.log(reg_num);
              console.log(this.femalearr)
            },
            // 价格计算
            rtotal:function(){
              //计算注册费价钱
              let author =0  //超页数
              let regmo =0
              let meelengs  = this.meetingArr.length
                for(let i = 0;i<this.femalearr.length;i++)
                {
                 if (this.femalearr[i].show){
                   author += parseInt(this.femalearr[i].reg_numb)
                   this.reg_numc=author
                 }
                }
                console.log(author)
              regmo=this.super_num*author
              // author*
              //计算参会费价钱
                let sum = 0;
                  sum= this.join_num*meelengs
                this.total=regmo+this.base_num+sum
                this.total=this.total.toFixed(2)
            },
            submit: function() {
              this.papert=[] //避免错误赋值为空
              // 稿件选中数据
              // for (let i =0;i<this.regArr.length;i++){
              //     this.regArr[i].papert.remove()
              // }
              for (let i =0;i<this.femalearr.length;i++){
                if (this.femalearr[i].show){
                  this.papert.push({number:this.femalearr[i].number,reg_numb:this.femalearr[i].reg_numb})
                }
              }
                let left = this.regpayt
                let right = this.meetingc
                if (left>1||right>1){
                    console.log('行')
                }else {
                    Toast({
                        message: '未选择注册费或参会费',
                        duration: 3000
                    });
                    return false;
                }
                if (this.regpayt==2){
                    var showsum = 0;
                    for(var i = 0;i<this.femalearr.length;i++)
                    {
                        if (this.femalearr[i].show){
                            showsum++
                        }
                    }
                    if (showsum==0){
                        Toast({
                            message: '注册费处缴费稿件未选择！！！',
                            duration: 3000
                        });
                        return false;
                    }
                }
              localStorage.setItem('base_num',this.base_num);
              localStorage.setItem('super_num',this.super_num);
              localStorage.setItem('join_num',this.join_num);
              localStorage.setItem('reg_numb',this.reg_numc);
              localStorage.setItem('meeting',this.meetingArr.length);
              localStorage.setItem('total',this.total);
              localStorage.setItem('regArr',JSON.stringify(this.regArr.data));
              localStorage.setItem('meetingArr',JSON.stringify(this.meetingArr));
              localStorage.setItem('papert',JSON.stringify(this.papert));
              localStorage.setItem('mid',this.data.id);
              localStorage.setItem('base_numb',this.base_numb);

                this.$router.push({name: 'order'
                 /* ,params:
                        {
                          base_num:this.base_num,//基础费用
                          super_num:this.super_num,//超页费用
                          join_num:this.join_num,//参会费用
                          reg_numb:this.reg_numc,//超页数
                          meeting:this.meetingArr.length,//参会费数量
                          total:this.total,//总数
                          regArr:this.regArr.data,//注册费表单数组
                          meetingArr:this.meetingArr,//参会费表单数组
                          papert:this.papert,//稿件
                          mid:this.data.id,//会议id
                        }
                        */
                })
                // var formData = JSON.stringify(this.user); // 这里才是你的表单数据
                //
                // this.$http.post('/admin/', formData).then((response) => {
                //   // success callback
                // }, (response) => {
                //   // error callback
                // });
                // return false;
                console.log(this.regArr)
                console.log(this.regArr.reg_num+'1111')
            },
        },
        watch:{
            // 'female.reg_num':function(index){
            //   console.log(index)
            //   let reg_num = parseInt(this.regArr.reg_num)
            //   console.log(reg_num)
            //   if (reg_num>this.femalenum) {
            //     this.regArr.reg_numc=reg_num-this.femalenum;
            //     this.rtotal();
            //   }else {
            //     this.regArr.reg_numc=0
            //     this.rtotal();
            //   }
            // },
            // female_reg_num:function () {
            //   console.log(this.female_reg_num)
            // }
        },
        beforeUpdate:function(){
            //这里不能更改数据，否则会陷入死循环
            // console.log('beforeUpdate:重新渲染之前触发')
            // console.log('然后vue的虚拟dom机制会重新构建虚拟dom与上一次的虚拟dom树利用diff算法进行对比之后重新渲染')
        },
        updated:function(){
            //这里不能更改数据，否则会陷入死循环
            // console.log('updated:数据已经更改完成，dom也重新render完成')
        },
        beforeDestroy:function(){
            // console.log('beforeDestory:销毁前执行（$destroy方法被调用的时候就会执行）,一般在这里善后:清除计时器、清除非指令绑定的事件等等...')
            // clearInterval(this.$options.timer)
        },
        destroyed:function(){
            // console.log('destroyed:组件的数据绑定、监听...都去掉了,只剩下dom空壳，这里也可以善后')
        }
    }
</script>
<style>
    .mint-toast-text{font-size: 32px;padding: 10px;}
</style>
<style lang="scss" scoped>
  body{
    background-color: #fff;
  }
  #form1{
    background-color: #fff;
  }
    input[type="radio" i] {
        -webkit-appearance: radio;
        margin: 3px 3px 0 5px; /*no*/
        display: inline-block;
        vertical-align: bottom;
    }
    input[type="checkbox" i] {
        margin: 3px 3px 3px 4px; /*no*/
        -webkit-appearance: checkbox;
        box-sizing: border-box;
    }
    *{
        font-size: 26px;
    }
    .left {
        float:left;
    }
    .registerf{
        padding: 20px;
        margin-bottom: 82px;
        .reg,.meeting{
            padding: 26px 20px;
            border: 1px solid #BCBCBC; /*no*/
            border-radius: 10px;
            clear: none;
            overflow: hidden;
            margin-bottom: 30px;
            .registerf_bottom_n{
                display: none;
            }
            .registerf_bottom_b{
                display: block;
            }
            .meeting_n{
                /*display: none;*/
            }
            .meeting_b{
                display: block;
            }
            .regtop{
                margin-bottom: 20px;
                .bg{
                    width: 50px;
                    height: 36px;
                    float: left;
                    display: inline-block;
                    background-image: url("../../common/image/officer/u3079.png");
                    background-repeat: no-repeat;
                    background-size: 100% 100%;
                }
                .tx{
                    font-size: 26px;
                    font-weight: 600;
                    margin-left: 20px;
                    height: 36px;
                    line-height: 36px;
                }
                .submit{
                    float: right;
                    width: 100px;
                    height:48px;
                    line-height: 48px;
                    background-color: #557ae4;
                    border-radius: 10px;
                    color: #fff;
                    text-align: center;
                }
                .submit_del{
                    background-color: #FF0000;
                }
                .meeting_del{
                    display: none;
                }
            }
            .regcenter{
                line-height: 40px;
                word-break: break-all;
                clear: none;
                overflow: hidden;
                .bg{
                    width: 50px;
                    height: 36px;
                    float: left;
                    display: inline-block;
                    background-image: url("../../common/image/officer/rmb.png");
                    background-repeat: no-repeat;
                    background-position: center;
                    background-size: 70%;
                    margin-right: 20px;
                }
                .tx{
                    margin-right: 40px;
                }
            }
            //注册费作者信息隐藏
            .registerf_hi{
                margin-top: 20px;
                border-top: 1px solid #C9C9C9; /*no*/
                padding: 30px 0 0 0;
                .registerf_t{
                    font-weight: 700;
                    color: #557ae4;
                    margin-bottom: 20px;
                }
                .calll{
                    height: 60px;
                    margin-bottom: 10px;
                }
                .cal{
                    width:24%;
                    line-height: 66px;
                }
                .car{
                    width:76%;
                    overflow: hidden;
                    border-bottom: 1px solid #BCBCBC;/*no*/
                }
                input{
                    width: 100%;
                    height: 60px;
                    line-height: 60px;
                }
            }
            //选择按钮处
            .reg_radio{
                margin-top: 20px;
                .femalew label{
                    line-height: 36px;
                    color: #5894C8;
                    input{
                        vertical-align: sub;
                    }
                }
                .reg_int{
                    margin-top: 10px;
                    margin-bottom: 20px;
                    .reg_num{
                        width: 80px;
                        border-bottom: 1px solid #BCBCBC;/*no*/
                        text-align: center;
                    }
                }
                .reg_radiob{
                    margin-top: 20px;
                    .gin_left{
                        width: 24%;
                        height: 40px;
                        line-height: 40px;
                        float: left;
                    }
                    .gin_right{
                        /*input[type="radio"]{*/
                        /*margin-left: 30px;*/
                        /*}*/
                        label:nth-child(n+2){
                            margin-left: 30px;
                        }
                    }
                    .submit{
                        width: 100px;
                        height:48px;
                        line-height: 48px;
                        border: none;
                        border-radius: 10px;
                        color: #fff;
                        text-align: center;
                    }
                    .addsubmit{
                        background-color: #557ae4;
                        display: inline-block;
                    }
                    .addsubmit_n{
                        display: inline-block;
                    }
                    .delsubmit{
                        display: inline-block;
                        background-color: #FF0000;
                        margin-left: 10px;
                    }
                }
                .reg_radiob_hide{
                    /*display: none;*/
                }
            }
        }
        /*底部*/
        .bottom{
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            overflow: hidden;
            clear: none;
            border-top: 1px solid #ddd; /*no*/
            background: hsla(0,0%,100%,.95);
            .bottom_f{
                float: left;
                width: 70%;
                text-align: center;
                height: 80px;
                line-height: 80px;
                /*background-color: #0099CC;*/
                span{
                    color: #FF0000;
                }
            }
            .bottom_r{
                input{
                    /*float: left;*/
                    width: 30%;
                    height: 80px;
                    line-height: 80px;
                    font-weight: 700;
                    font-size: 32px;
                    background-color: #FF0000;
                    text-align: center;
                    color: #fff;
                    letter-spacing:8px;
                }
            }
        }
    }
</style>
